var common = {};
common.resizeIframe = function(iframeDom) {
	var $iframe = $(iframeDom).filter(':visible'), $body = $iframe.contents()
			.find('body');
	if ($iframe.size()) {
		var w = $body.width(), h = $body.height();
		if (w > 0 && h > 0)
			$iframe.width(w).height(h);
	}
};
common.validator = function(formId) {
	$("#" + formId).validate({
		highlight : function(element, errorClass) {
			$(element).css("border-color", "red");
			$(element).val('');
			$(element).fadeOut(function() {
				$(element).fadeIn();
			});
		},
		unhighlight : function(element, errorClass) {
			$(element).css("border-color", "");
		}
	});
};

common.checkBlankValue = function(allarr, chkfield) {
	var arry = allarr.split("&");
	var canSubmit = true;
	for (i = 0; i < arry.length; i++) {
		var ary = arry[i].split("=");
		if ($.inArray(ary[0], chkfield) != -1) {
			if (!ary[1] && ary[1]=="") {
				canSubmit = false;
				return false;
			}
		}
	}
	return canSubmit;
};

common.getValueByFieldName = function(allarr, fieldName) {
	var arry = allarr.split("&");
	for (i = 0; i < arry.length; i++) {
		var ary = arry[i].split("=");
		if (ary[0] == fieldName) {
			return ary[1];
		}
	}
	return "";
};

common.clearTextRequiredClass=function(formId){
	$("input[type=text]","#"+formId).each(function(){
		$(this).removeClass("required");
	});
};

common.addTextRequiredClass=function(formId){
	$("input[type=text]","#"+formId).each(function(){
		$(this).addClass("required");
	});
};

common.tipWithAutoClose=function(divId){
	$('#'+divId).wijdialog('open');
	setTimeout("$('#"+divId+"').wijdialog('close')", 3000);
};

common.initDialog=function(divId){
	$("#"+divId).wijdialog({
		autoOpen : false,
		height : 260,
		width : 480,
		modal : true
	});
};

common.initDelDialogMsg=function(msg){
	$('#delete-dialog  p').append(msg);
};

common.proccessMsg = function(showMsgCtxId, msg, tips) {
	var showMsgContextId = $("#" + showMsgCtxId);
	if (msg == "success") {
		showMsgContextId.html(tips + "操作成功！");
	} else if (msg == "exists") {
		showMsgContextId.html(tips + "操作已存在！");
	} else {
		showMsgContextId.html(tips + "操作失败！");
	}
};
